﻿using RabbitMQClient;
using System;
using System.Threading.Tasks;

namespace RpcClientConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("RPC Client");
            Task task1 = InvokeAsync(1);
            Task task2 = InvokeAsync(3);
            Task task3 = InvokeAsync(5);
            Task task4 = InvokeAsync(4);
            Task task5 = InvokeAsync(2);
            Task task6 = InvokeAsync(8);
            Task.WaitAll(task1, task2, task3, task4, task5, task6);

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }
        private static async Task InvokeAsync(int n)
        {
            Console.WriteLine(" [{0}] Request '{1}'", System.Threading.Thread.CurrentThread.ManagedThreadId, n);
            RabbitMQClient.IRabbitMQClient client = new RabbitMQClient.RabbitMQClient(
                host: "localhost",
                port: 5672,
                userName: "root",
                passowrd: "123456"
            );
            var rpc = client.StartRpcChannel<RequestModel, ResponseModel>();
            var response = await rpc.CallAsync("rpc_queue", new RequestModel() { a = n });
            Console.WriteLine(" [{0}] Got '{1}'", System.Threading.Thread.CurrentThread.ManagedThreadId, response.a);
            rpc.Close();
        }
    }
}
